/**
 * 
 */
package qzsmk;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import com.lanswon.qzsmk.service.commonservice.LossCardInfo;
import com.lanswon.qzsmk.service.commonservice.impl.DockingInternetService;

/**
 * @author sun
 *
 */
public class test {

	public ApplicationContext context= null;
	
	DockingInternetService qq;

	@Before
	public void init(){
		context = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
		qq = context.getBean(DockingInternetService.class);
	}
	
	@After
	public void destroy(){
		context = null;
	}
	
	
	@Test
	public void test(){
		LossCardInfo lci = new LossCardInfo();
		lci.setPaperType("00");
		lci.setPaperNo("320283198810286112");
		lci.setStartLine(0);
		lci.setCurrentPage(1);
		lci.setNumPerPage(10);
		
		qq.queryLossCard(lci);
	}
	

   
    
 public static void main(String[] args) throws Exception {
        
        Properties prop = new Properties();
        prop.setProperty("mail.host", "smtp.qq.com");
        prop.setProperty("mail.transport.protocol", "smtp");
        prop.setProperty("mail.smtp.auth", "true");
        prop.setProperty("mail.smtp.auth", "true");
        //使用JavaMail发送邮件的5个步骤
        //1、创建session
        Session session = Session.getInstance(prop);
        //开启Session的debug模式，这样就可以查看到程序发送Email的运行状态
        session.setDebug(true);
        //2、通过session得到transport对象
        Transport ts = session.getTransport();
        //3、使用邮箱的用户名和密码连上邮件服务器，发送邮件时，发件人需要提交邮箱的用户名和密码给smtp服务器，用户名和密码都通过验证之后才能够正常发送邮件给收件人。
        ts.connect("smtp.qq.com", "1345625601@qq.com", "dklzgbuackyqbhbb");
        //4、创建邮件
        Message message = createSimpleMail(session);
        //5、发送邮件
        ts.sendMessage(message, message.getAllRecipients());
        ts.close();
    }
 
 public static MimeMessage createSimpleMail(Session session)
         throws Exception {
     //创建邮件对象
     MimeMessage message = new MimeMessage(session);
     //指明邮件的发件人
     message.setFrom(new InternetAddress("1345625601@qq.com"));
     //指明邮件的收件人，现在发件人和收件人是一样的，那就是自己给自己发
     message.setRecipient(Message.RecipientType.TO, new InternetAddress("208283264@qq.com"));
     //邮件的标题
     message.setSubject("只包含文本的简单邮件");
     //邮件的文本内容
     message.setContent("你好啊！", "text/html;charset=UTF-8");
     //返回创建好的邮件对象
     return message;
 }
	
}

